<?php $this->Html->addCrumb('Product Sold Lists'); ?>
<style type="text/css">
td p span{color:#00B050;}
td.vendor h2 {font-size:20px; color: #00B050;}
</style>
<div class="global-title">Product sold lists</div>
<?php if(!empty($solds)): ?>
<?php echo $this->Form->create('Product', array('action' => 'search_sold')); ?>
<br /><input type="text" name="data[keywords]" value="Enter Item #, Product Title or Buyer ID"  onblur="if(this.value=='') this.value='Enter Item #, Product Title or Buyer ID'" onfocus="if(this.value=='Enter Item #, Product Title or Buyer ID') this.value='';" size="50" />
<select name="data[search_by]">
<option value="">Search BY</option>
<option value="item_title">Item Title</option>
<option value="item_number">Item Number</option>
<option value="buyer_id">Buyer ID</option>
</select>
<input type="submit" name="searchSubmit" value="Search" />
</form>
<a href="javascript:void(0);" controller="products" action="addsoldnote_selected" title="messagebyitem" onclick='showPop(this)'><input type="button" value="Add Note to Selected" /></a>
<div class="resultarea">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="sold_table" class="tablesorter">
	<thead>
		<tr>
			<th style="width:auto;"><input type="checkbox" id="select_all" /></th><th style="width:auto;">&nbsp;</th>
			<th style="width:auto;">(Item #)Title</th><th style="width:auto;">Buyer ID</th>
			<th style="width:auto;">Qty</th><th style="width:auto;">Price</th>
			<th style="height:35px;width:auto;">Total Price</th>
			<th style="height:35px;width:auto;">Sale Date</th>
			<th style="width:auto;">Order ID</th><th style="width:auto;">Tracking #</th><th style="width:auto;">Carrier</th><th style="width:auto;">Action</th>
		</tr>	
	</thead>	
	<tbody> 
	<?php $i=0;foreach($solds as $sold):
		$class = 'even';
		if ($i++ % 2 == 0)
			//$class = 'odd';
	?>
	<tr id="row_<?php echo $sold['Cart']['id'];?>" class="<?php echo $class;?>">
		<td><input type="checkbox"  class="products_id"  id="sold_id" value="<?php echo $sold['Product']['id']; ?>" /></td>
		<td><img src="<?php echo Configure::read('base_url');?>img/thumbs/<?php echo $sold['Product']['products_thumbnailImage'];?>" alt="<?php echo $sold['Product']['products_title'];?>" /></td>
		<td><a href="<?php echo Configure::read('base_url');?>products/details/<?php echo $sold['Product']['id'];?>" target="_blank" title="<?php echo $sold['Product']['products_title'];?>">(<?php echo $sold['Product']['id'];?>) <?php echo $sold['Product']['products_title'];?></a></td>
		<td><?php echo $sold['User']['first_name']." ".$sold['User']['last_name'];?></td>
		<td><?php echo $sold['Cart']['quantity'];?></td>
		<td>US $<?php echo $sold['Cart']['product_cost'];?></td>
		<td>US $<?php echo ($sold['Cart']['product_cost']*$sold['Cart']['quantity']);?></td>
		<td><?php echo date("m-d-Y",strtotime($sold['Order']['add_date']));?></td>
		<td><?php echo $sold['Order']['id'];?></td>
		<td><?php echo $sold['Order']['transaction_id'];?></td>
		<td><?php echo $sold['Shipping']['shipping_method'];?></td>
		<td>
			<a href="<?php echo Configure::read('base_url');?>products/sell_similar/<?php echo $sold['Product']['id'];?>">Sell Similar</a><br />
			<a href="javascript:void(0);" controller="products" action="add_tracking" ElmID="<?php echo $sold['Order']['id']; ?>" onclick="showPop(this)" title="Add Tracking">Add Tracking</a><br />
			<a href="javascript:void(0);" controller="products" action="contact_buyer" title="Contact Buyer" onclick="showPop(this)"  ElmID="<?php echo $sold['Product']['id']; ?>" onclick='showPop(this)'>Contact Buyer</a>
            <a href="javascript:void(0);" controller="products" action="create_dispute" title="create_dispute"
               ElmID="<?php echo $sold['Product']['id']; ?>" ElmID2="<?php echo $sold['Cart']['id']; ?>" onclick='showPop(this)'>
            <input type="button" value="dispute" /></a>
		</td> 				
		</tr>
		<?php
        $comments = $this->requestAction('/products/getsoldnote/'.$sold['Product']['id'].'/'.$session->read('Auth.User.id'));
        
        if (!empty($comments)) {
        ?>
		<tr class="fullrow<?php echo $sold['Product']['id']; ?>" >
            <td colspan="12" id="disnote<?php echo $sold['Product']['id']; ?>" style="background: none repeat scroll 0pt 0pt BlanchedAlmond;text-align: left;">
			<?php
			foreach($comments as $comment) {
				echo '<b>'.'My Note'.' [ '.date('m-d-Y',  strtotime($comment['Soldnote']['created'])).' ] : </b> '.$comment['Soldnote']['note'];echo"<br/>";
			}
		?>
		</td></tr>
		<?php
        }
        ?>			
		<?php endforeach;?>						
	</tbody> 	
</table>
<?php else:?>
<br /><br />
<h2>Your sold list is empty.</h2>
<br /><br /><br />
<?php endif;?>
<div class="paging">
    <?php
		echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?> | 
	<?php echo $this->Paginator->numbers();?>
		| 
	<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>
</div>
<?php echo $this->Html->css('table_css');?>  

<?php  echo $html->script(array("jquery.tablesorter.min.js","jquery.tablednd.js")); ?>	 
 <script type="text/javascript"> 
 jQuery(document).ready(function(){
 jQuery("#sold_table").tablesorter({headers: { 0:{sorter: false}, 1:{sorter: false}, 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false},8:{sorter: false},9:{sorter: false},10:{sorter: false},11:{sorter: false}}}); 
 jQuery("#select_all").live('click', function(){
	var checked_status = this.checked;
	jQuery("input[id=sold_id]").each(function()
	{
		this.checked = checked_status;
	});
});
jQuery('[name="searchSubmit"]').click(function(){
    dataString=jQuery("#ProductSearchSoldForm").serialize();
    jQuery.ajax({
        type:"post",
        url: baseurl+"/products/search_sold",
        data:dataString,
        success: function(data){
            jQuery(".resultarea").empty();
            jQuery(".resultarea").append('<img src="<?php echo  $this->webroot;?>img/loading.gif" alt="loading" class="loading" />');
            jQuery(".resultarea").append(data);
            jQuery(".loading").remove();
        }
    });
    return false;    
});
 });
 </script>
<style type="text/css">

    table.tablesorter tbody tr.even td {
        border: none;
}
table.tablesorter {
    background-color: #fff;
}
</style>